max값의 처리 :: 오라클 실습[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

오라클 실습
[1]
등록일:2009-05-28 00:13:25 (0%)
작성자:
제목:max값의 처리
가장  효율적인  MAX값처리를  위해  Index된  컬럼을  이용한다.

예)    select  stock_q  
  from  GFLM600  a  
                  where  io_date  =  (select  max(io_date)
                from  GFLM600  b
where  b.car_code  =  :value1
    and  b.box_code  =  :value2
    and  a.car_code  =  b.car_code
    and  a.box_code  =  b.box_code);  2번  테이블을  읽어야  한다.
    (개선안)  
  select  /*+  index_desc(a  GFLM600_PK)  :car_code  +  box_code  +  io_date  */      stock_q  
        from  GFLM600  a
      where  car_code  =  :value1
          and  box_code  =  :value2
          and  rownum  =  1;

  max-min에서  sql분리
반드시  두개의  SQL문을  합쳐서  수행해야  좋은  성능을  얻는  것은  아니다.  다음의  경우는  분리하여  수행할  때  보다  만족한  성능을  얻는  경우이다.

-  THISEQPM  :  THISEQPM_X1  =  EQPMDEPT  +  EQPMPART  +  EQPMROOM

select  (max(eqpmroom)  –  min(eqpmroom))  +  1  into  :nextroom
from  thiseqpm
where  eqpmdept  =  :value1
        and  eqpmpart  =  :value2;

<개선안1>  :  Max,  Min의  분리
Select  /*+  index_desc  (thiseqpm  thiseqpm_x1)  */
              Eqmproom  into  max_room
From  thiseqpm
Where  eqpmdept  =  :value1  and  eqpmpart  =  :value2
And  rownum=1;

Select  /*+  index_asc  (thiseqpm  thiseqpm_x1)  */
            Eqmproom  into  min_room
From  thiseqpm
Where  eqpmdept  =  :value1  and  eqpmpart  =  :value2
And  rownum=1;

<개선안2>  In-line  View를  이용하여  하나의  SQL로  작성
&#61664;  select  /*+  index_asc(a  thiseqpm_x1)  */    inv.max_room  &#8211;  a.eqpmroom  +  1
          from  (select  /*+  index_desc(thiseqpm  thisqpm_x1)  */  eqpmroom  as  max_room
                                  from  thisqpm
                                where  eqpmdept  =  :value1
                                      and  eqpmpart  =  :value2
                                      and  rownum  =  1)  inv,  
            thiseqpm  a
where  eqpmdept  =  :value1
      and  eqpmpart  =  :value2
and  rownum  =  1;
  
&#61482;  현재일자를  where에  넣고싶은  경우는  varchar2로  잡으면  편리하다.  
              To_char(sysdate,’yyyymmdd’)
[본문링크] max값의 처리
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=31498
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.